#include<stdio.h>

typedef unsigned char *byte_pointer;

unsigned replace_byte(unsigned x,unsigned char b,int i){
    int mask = 0x000000FF;
    unsigned shift_val = (i - 1) * 8;

    mask <<= shift_val;

    return (x & (~mask)) | (b << shift_val);

}

void show_bytes(byte_pointer start, int len) {
    int i;
    for (i = 0; i < len; i++)
        printf(" %.2x", start[i]);    //line:data:show_bytes_printf
    printf("\n");
}

int main(){
    unsigned x = 0x12345678;
    unsigned char b = 0xAB;
    byte_pointer pointer = (byte_pointer)&x;

    show_bytes(pointer,sizeof(unsigned));

    int i;
    for(i = 1;i < 5; ++i){
        unsigned result = replace_byte(x,b,i);
        pointer = (byte_pointer)&result;
        show_bytes(pointer,sizeof(unsigned));
    }
    return 0;
}
